package com.zhu.classfile.constant.base;

import com.zhu.classfile.constant.ConstantInfo;
import com.zhu.classfile.constant.ConstantPool;
import com.zhu.classfile.constant.ConstantTag;

import java.nio.ByteBuffer;

//CONSTANT_MethodType_info
public class ConstantMethodTypeInfo implements ConstantInfo {
    private final ConstantTag tag = ConstantTag.CONSTANT_MethodType;
    private final ConstantPool cp;
    private int descriptorIndex;

    public ConstantMethodTypeInfo(ConstantPool cp) {
        this.cp = cp;
    }

    @Override
    public void readInfo(ByteBuffer reader) {
        descriptorIndex = Short.toUnsignedInt(reader.getShort());
    }

    public String getDescriptor() {
        ConstantUtf8Info utf8 = (ConstantUtf8Info) cp.get(descriptorIndex);
        return utf8.getValue();
    }

    @Override
    public ConstantTag getTag() {
        return tag;
    }
}
